package com.shinetech.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
    /**
     * 直接访问静态资源
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/admin/**").addResourceLocations(
                "classpath:/static/*");
        super.addResourceHandlers(registry);
    }

    /**
     * 对于一些不需要业务处理的视图，可以不需要相关controller类，直接访问相关视图。类似
     * @RequestMapping("about")
     * public String about(){
     *     return "about"
     * }
     * @param registry
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.setOrder(-1);
        super.addViewControllers(registry);
        registry.addViewController("/index").setViewName("index");
        registry.addViewController("/about").setViewName("about");
        registry.addViewController("/userlist").setViewName("user/list");
        registry.addViewController("/user/edit").setViewName("user/edit");
        registry.addViewController("/menulist").setViewName("menu/list");
        registry.addViewController("/menu/edit").setViewName("menu/edit");
        registry.addViewController("/grouplist").setViewName("group/list");
        registry.addViewController("/group/user").setViewName("group/user");
        registry.addViewController("/group/authority").setViewName("group/authority");
        registry.addViewController("/group/edit").setViewName("group/edit");
        registry.addViewController("/groupType").setViewName("groupType/list");
        registry.addViewController("/groupType/edit").setViewName("groupType/edit");
        registry.addViewController("/element/edit").setViewName("element/edit");
        registry.addViewController("/gateClient").setViewName("gateClient/list");
        registry.addViewController("/gateClient/edit").setViewName("gateClient/edit");
    }
}
